layui.use(['laydate','form','laypage','table','upload'], function(){
    var laydate = layui.laydate;
    var  form = layui.form,
    laypage = layui.laypage,
    upload = layui.upload,
    table = layui.table;
    ctx = $("#baseurl").val();

    /**
     * input点击事件，显示保存按钮
     */
    $(document).on("click",".userFull",function () {
        $(".luckSave").css("display", "none")
        $(this).parent("td").children("a").css({"display":"inline","width":"100px"});
    })

    /**
     * 保存姓名
     */
    $(document).on("click",".luckSave",function () {
        $(".luckSave").css("display", "none")
        var userFull = $(this).parent("td").children("input").val();
        var id = $(this).parent("td").children("span").attr("id");
        console.log("值："+userFull+",id:"+id);
        _updateUserFull(id,userFull);
    })

    //导出
    $("#export").click(function () {
        // $("#_ldId").val($("#ldId").val()); //
        // $("#_barckNo").val($("#barckNo").val()); //批次号
        // $("#_ldNo").val($("#ldNo").val()); //签号
        // $("#_userFull").val($("#userFull").val()); //姓名
        // $("#_isCar").val($("#isCar").val()); //是否原有车位
        // $("#_creatTime").val($("#creatTime").val()); //数据生成时间
        // $("#_updateTime").val($("#updateTime").val()); //数据修改时间
        //$("#_tradeAccountId").val($("#tradeAccountId option:selected").val());//下拉框请放开此项进行修改
        $("#reportsub").submit();
    });
});

function choujiang(){
    $("#choujiangbtu").text("正在生成中奖号码.....")
    //生成号码
    $.ajax({
        url: $("#baseurl").val() + '/add',
        data: {},
        type: 'post',
        success: function (data) {
            if(data.code==20000){
                var i = 1;
                var myclean = setInterval(function(){
                    $.ajax({
                        url: $("#baseurl").val() + '/getOneLuck',
                        data: {"ldId":i},
                        type: 'post',
                        success: function (data) {
                            var msg = data.msg;
                            var luck = data.data;
                            console.log(msg);
                            $("#ldNo"+i).text(luck.ldNo);
                            i++;
                            if (i>22){
                                clearInterval(myclean);
                                layer.confirm('本轮抽奖结束');
                                $("#choujiangbtu").text("点击抽奖")
                            }
                        }
                    });
                },3000);
            }else{
                layer.confirm('数据加载异常....');
                $("#choujiangbtu").text("点击抽奖")
            }
        }
    });
}

/**
 * 更新姓名信息
 * @private
 */
function _updateUserFull(id,userFull){
    $.ajax({
        url: $("#baseurl").val() + '/edit',
        data:  {
            "ldId":id,
            "userFull":userFull
        },
        type: 'post',
        success: function (data) {
            layer.msg(data.msg,{icon:1,time:1000});
        }
    });
}

/**
 * 更新是否愿车位信息
 * @param obj
 * @param id
 * @param iscar
 * @private
 */
function _updateIsCar(obj,id,iscar){
    console.log("id:"+id+",是否原来车位："+iscar);
    $.ajax({
        url: $("#baseurl").val() + '/edit',
        data:  {
            "ldId":id,
            "isCar":iscar
        },
        type: 'post',
        success: function (data) {
            layer.msg(data.msg,{icon:1,time:1000});
        }
    });
}

